<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>VUE Template</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2 :style="{opacity: myopacity}">欢迎学习Vue</h2>
    </div>
</body>
    <script type="text/javascript">
        
        const vm = new Vue({
            el:'#root',
            data:function(){
                return{
                    myopacity:1
                }
            },
            methods:{

            },
            // vue完成模板解析并把【初始的】真实DOM元素放入页面后(挂载完毕)调用mounted
            mounted() {
                setInterval(()=>{
                    //console.log("setInterval");
                    this.myopacity -=0.01
                    if (this.myopacity<=0) {
                        this.myopacity=1
                    }
                },16)
            },
        })

        // 通过外部的定时器实现（不推荐）
        // setInterval(()=>{
        //     vm.myopacity -=0.01
        //     if (vm.myopacity<=0) {
        //         vm.myopacity=1
        //     }
        // },16)
    </script>
</html>